<?php

class ectools_refund_update {

    public function __construct($app) {
        $this->app = $app;
    }

    public function generate(&$sdf) {
        // 退款单修改是和中心的交互
        $objRefunds = $this->app->model('refunds');
        $data['refund_id'] = $sdf['refund_id'];
        $data['trade_no'] = $sdf['trade_no'];
        $data['t_payed'] = $sdf['t_payed'];
        $data['status'] = ($sdf['status'] == 'succ' || $sdf['status'] === true) ? 'succ' : 'failed';
        
        $filter = array(
            'refund_id' => $sdf['refund_id'],
            'status|noequal' => 'succ',
            'status|noequal' => 'progress'
        );
        
        $is_save = $objRefunds->update($data, $filter);
        
        if ($is_save) {
            if ($objRefunds->db->affect_row())
                return true;
            else
                return false;
        } else {
            $msg = app::get('ectools')->_('支付单修改失败！');
            return false;
        }
    }
}